<?php

namespace backend\models\course;

use Yii;
use backend\models\course\Course;
/**
 * This is the model class for table "{{%edu_course_period}}".
 *
 * @property integer $period_id
 * @property integer $joint_id
 * @property integer $period_num
 * @property string $period_name
 * @property integer $period_addtime
 * @property string $movie_datum
 * @property string $movie_url
 * @property integer $period_updtime
 * @property integer $movie_status
 */
class CoursePeriod extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%course_period}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['period_name'],'required'],

            [['joint_id','length_minute','open_time','end_time','length_second','course_id', 'period_num', 'period_addtime', 'period_updtime', 'movie_status'], 'integer'],
            [['period_name', 'period_datum', 'movie_url','movie_name'], 'string', 'max' => 100]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'period_id'      => 'Period ID',
            'joint_id'       => 'Joint ID',
            'period_num'     => 'Period Num',
            'period_name'    => '课时名称',
            'period_addtime' => 'Period Addtime',
            'period_datum'   => 'Movie Datum',
            'movie_name'     => '视频',
            'movie_url'      => '视频地址',
            'period_updtime' => 'Period Updtime',
            'movie_status'   => 'Movie Status',
            'length_minute'  =>'分',
            'length_second'  =>'秒',
            'course_id'      => 'Course ID',
            'open_time'      =>'开课时间',
            'end_time'       =>'结束时间',
        ];
    }

	/* 新增课时数  今日 */
	static public function TodaySection($today_start,$today_end)
	{
		return CoursePeriod::find()
				->where("period_addtime>= :today_start and period_addtime<= :today_end",
				[':today_start'=>$today_start,':today_end'=>$today_end])
				->count();
	}

	/* 新增课时数  昨日 */
	static public function YesterdaySection($yesterday_start,$yesterday_end)
	{
		return CoursePeriod::find()
				->where("period_addtime>= :yesterday_start and period_addtime<= :yesterday_end",
				[':yesterday_start'=>$yesterday_start,':yesterday_end'=>$yesterday_end])
				->count();
	}
    /**/
    public function getCourse()
    {
         return $this->hasOne(Course::className(),['course_id'=>'course_id'])
                        ->where('type_id = 11');
    }

}
